package filmring

class SearchController {

    def searchService

    def index = {

    }

    def show ={
        List<Movie> movies = searchService.searchMovies(params.query)
        List<Actor> actors = searchService.searchActors(params.query)
        List<Director> directors = searchService.searchDirectors(params.query)
        List<Rating> ratings = new ArrayList<Rating>()
        FRUser user = FRUser.get(params.id as Long)
        for(Movie movie :movies){
            Rating rating = Rating.findByUserAndMovie(user,movie)
            if(rating==null){
                rating= new Rating(movie:movie, user:user, rating:0)
            }
            ratings.add(rating)
        }
        if(user==null){
            session.user=0
        }
        render(view:"show", model:[user:user, ratings:ratings, movies:movies, actors:actors, directors:directors, query:params.query])
    }
}
